package sgi.client;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JTextField;
import javax.swing.JButton;

public class SGILoginUI extends JFrame {

	private JPanel contentPane;
	private JTextField textFieldUser;
	private JTextField textFieldPassword;
	private JTextField textFieldNotification;
	private SGILoginController loginController;


	public SGILoginUI() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 445, 257);
		contentPane = new JPanel();
		setTitle("SGI Client-Login");
		contentPane.setLayout(null);
		setContentPane(contentPane);
		
		JLabel lblUsername = new JLabel("Username:");
		lblUsername.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblUsername.setBounds(58, 40, 72, 14);
		contentPane.add(lblUsername);
		
		JLabel lblPassword = new JLabel("Password:");
		lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblPassword.setBounds(58, 67, 72, 14);
		contentPane.add(lblPassword);
		
		textFieldUser = new JTextField();
		textFieldUser.setBounds(140, 38, 114, 20);
		contentPane.add(textFieldUser);
		textFieldUser.setColumns(20);
		
		textFieldPassword = new JPasswordField();
		textFieldPassword.setColumns(20);
		textFieldPassword.setBounds(140, 65, 114, 20);
		contentPane.add(textFieldPassword);
		
		JButton btnLogin = new JButton("Login");
		btnLogin.setBounds(58, 109, 89, 23);
		btnLogin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					loginController.handleMessageFromLoginUI(textFieldUser.getText(), textFieldPassword.getText());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}});
		contentPane.add(btnLogin);
		
		
		
		JButton btnRegister = new JButton("Register");
		btnRegister.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SGILoginController.terminate();
				SGIRegisterController.createRegister();
			}
		});
		btnRegister.setBounds(277, 109, 89, 23);
	/*	btnRegister.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
						registrationController.createRegister();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}});*/
		contentPane.add(btnRegister);
		
		textFieldNotification = new JTextField();
		textFieldNotification.setBounds(61, 156, 305, 20);
		contentPane.add(textFieldNotification);
		textFieldNotification.setColumns(10);
		textFieldNotification.setEditable(false);
		
	}
	
	public void setNotification(String s)
	{
		textFieldNotification.setText(s);
	}

	public void setLoginController(SGILoginController loginController) {
		this.loginController = loginController;
	}

}
